package cc.javaee.bbs.vo;

import cc.javaee.bbs.model.Bankuai;
import cc.javaee.bbs.model.activity.BankuaiCustomer;
import lombok.Data;
import org.apache.commons.collections.CollectionUtils;

import java.util.List;

/**
 * @author xdw
 */
@Data
public class CircleVO {

    private Integer id;         //圈子ID

    private String imgPath;     //圈子文件

    private String name;        //圈子名称

    private Integer count;      //参与人数

    private Integer myStatus;   //我的参与状态  0未参与 1已参与

    public static CircleVO conversionBankuai(Bankuai bankuai, String archivalNumber) {
        CircleVO circle = new CircleVO();
        circle.setId(bankuai.getId());
        circle.setImgPath(bankuai.getImg());
        circle.setName(bankuai.getName());
        circle.setCount(bankuai.getBankuaiCount());
        Integer myStatus = 0;
        List<BankuaiCustomer> bankuaiCustomers = bankuai.getBankuaiCustomers();
        if (CollectionUtils.isNotEmpty(bankuaiCustomers) && archivalNumber != null) {
            long count = bankuaiCustomers.stream().filter(e -> archivalNumber.equals(e.getArchivalNumber())).count();
            if (count > 0) {
                myStatus = 1;
            }
        }
        circle.setMyStatus(myStatus);
        return circle;
    }

}
